package LEETCODE2023.BISHUA100;

import java.util.PriorityQueue;
import java.util.Queue;

public class 第K大的数 {
    /*

    优先队列默认为小项堆
    
     */
    public int getKbignumber(int[] arr, int k) {
        Queue<Integer> heap = new PriorityQueue<>();
        for (int e : arr) {
            if (heap.isEmpty() || heap.size() < k || e < heap.peek()) {
                heap.offer(e);
            }
            if (heap.size() > k) {
                heap.poll();
            }
        }
        return heap.poll();
    }
}
